<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

date_default_timezone_set('PRC');

require_once 'Zend/Config/Ini.php';

$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
require_once 'Zend/Registry.php';
Zend_Registry::set("config",$config);

//Zend_Layout::startMvc();


/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    $config
);


$logDir = $config->get('log')->get('path');
is_dir($logDir)||mkdir($logDir);


$format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
$formatter = new Zend_Log_Formatter_Simple($format);
$writer = new Zend_Log_Writer_Stream($logDir."log_".Date("Y-m-d").".log");
$writer->setFormatter($formatter);
$logger = new Zend_Log($writer);

//注册logger
Zend_Registry::isRegistered("logger")||Zend_Registry::set("logger",$logger);
//auto load files under library\base
Zend_Loader_Autoloader::getInstance()->registerNamespace(array("Base_"));

$application->bootstrap()
            ->run();